package BaseObject.signleTon;

/**
 * ClassName: SingleTon01 饿汉式
 * Package: BaseObject.signleTon
 * Description:
 *
 * @Author Linshio
 * @Create 2025/3/22 11:11
 */
public class SingleTon01 {
    public static void main(String[] args) {
        GirlFriend instance = GirlFriend.getInstance();
        GirlFriend instance1 = GirlFriend.getInstance();
        System.out.println("instance = " + instance);
        System.out.println("instance1 = " + instance1);
        System.out.println(instance1==instance);
    }
}

class GirlFriend{
    private String name;

    private static GirlFriend gl = new GirlFriend("AZ");

    private GirlFriend(String name){
        this.name = name;
    }

    public static GirlFriend getInstance(){
        return gl;
    }

    @Override
    public String toString() {
        return "GirlFriend{" +
                "name='" + name + '\'' +
                '}';
    }
}
